<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<style>
    .animate{
        transition: width 3s;
        width: 100px;
        height: 100px;
        background: pink;
    }
</style>
<body>
    <button onclick="changeWidth()">改变宽度</button>
    <br>
    <div class="animate" id="demo"></div>
</body>
<script>
    function changeWidth(){
        document.getElementById("demo").style.width="300px"
    }
</script>
</html>